/**
 * 车辆管理API接口
 */

import { requestClient } from '#/api/request';

/**
 * 车辆状态枚举
 */
export enum VehicleStatus {
  AVAILABLE = '可用',
  DISABLED = '停用',
  IN_USE = '出车中',
  MAINTENANCE = '维保中',
}

/**
 * 车辆信息接口
 */
export interface Vehicle {
  vehicleId: number;
  licensePlate: string;
  brand?: string;
  model?: string;
  color?: string;
  purchaseDate?: string;
  insuranceDue?: string;
  inspectionDue?: string;
  status: VehicleStatus;
  fuelConsumption?: number;
  driverName?: string;
}

/**
 * 车辆查询参数
 */
export interface VehicleQueryParams {
  licensePlate?: string;
  status?: VehicleStatus;
  brand?: string;
  model?: string;
  color?: string;
  driverName?: string;
  page?: number;
  pageSize?: number;
}

/**
 * 车辆分页响应
 */
export interface VehiclePageResponse {
  list: Vehicle[];
  total: number;
  page: number;
  pageSize: number;
}

/**
 * 车辆表单数据
 */
export interface VehicleFormData {
  licensePlate: string;
  brand?: string;
  model?: string;
  color?: string;
  purchaseDate?: string;
  insuranceDue?: string;
  inspectionDue?: string;
  status: VehicleStatus;
  fuelConsumption?: number;
}

/**
 * 获取车辆列表
 */
export async function getVehiclesApi(
  params: VehicleQueryParams,
): Promise<VehiclePageResponse> {
  return requestClient.get<VehiclePageResponse>('/vehicles/list', { params });
}
/**
 * 获取可用车辆列表
 */
export async function getAvailableVehiclesApi(
): Promise<VehiclePageResponse> {
  return requestClient.get<VehiclePageResponse>('/vehicles/available');
}
/**
 * 创建车辆
 */
export async function createVehicleApi(
  data: VehicleFormData,
): Promise<Vehicle> {
  return requestClient.post<Vehicle>('/vehicles', data);
}

/**
 * 更新车辆
 */
export async function updateVehicleApi(
  id: number,
  data: VehicleFormData,
): Promise<Vehicle> {
  return requestClient.put<Vehicle>(`/vehicles/${id}`, data);
}

/**
 * 删除车辆
 */
export async function deleteVehicleApi(id: number): Promise<void> {
  return requestClient.delete(`/vehicles/${id}`);
}

/**
 * 检查车牌号是否已存在
 */
export async function checkLicensePlateExistsApi(
  licensePlate: string,
): Promise<boolean> {
  return requestClient.get<boolean>('/vehicles/check-license-plate', {
    params: { licensePlate },
  });
}
